<#assign ctx=request.contextPath />
<!doctype html>
<html class="no-js fixed-layout">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="keywords" content="index">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" href="${ctx}/bootstrap/css/bootstrap.min.css">
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-sm-12 col-md-12 col-lg-12">
					<form class="form-horizontal" id="dataForm" method="post">
						<input type="hidden"  id="id" name="id" value="<#if record??>${record.id}</#if>"/> 
						<div class="form-group">
							<label for="name" class="col-sm-2 control-label">所属APP</label>
							<div class="col-sm-9">
								<select id="appId" name="appId" class="form-control" <#if readOnly??>readOnly</#if>>
										<#list registers as register>
											<option value="${register.id}">${register.appCode}__${register.appName}</option>
										</#list>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label for="name" class="col-sm-2 control-label">代码名称</label>
							<div class="col-sm-9">
								<input type="text" class="form-control" name="codeName" id="codeName" value="<#if record??>${record.codeName}</#if>"/>
							</div>
						</div>
						<div class="form-group">
							<label for="name" class="col-sm-2 control-label">代码描述</label>
							<div class="col-sm-9">
								<textarea rows="4" class="form-control" id="codeDesc" name="codeDesc"><#if record??>${record.codeDesc}</#if></textarea>
							</div>
						</div>
						<div class="form-group">
							<span class="col-sm-5"></span>
							<div class="col-sm-5">
								<button type="button" id="submit" class="btn btn-primary">提交</button>
							</div>
						</div>
					</form>						
			</div>
		</div>
	</div>

	<script src="${ctx}/jquery/jquery.min.js"></script>
	<script src="${ctx}/bootstrap/js/bootstrap.min.js"></script>
	<script src="${ctx}/layer/layer.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#submit").click(function() {
				var appId = $("#appId").val();
				var codeName = $("#codeName").val();
				var codeDesc = $("#codeDesc").val();
				if (null == appId || '' == appId || undefined == appId) {
					layer.alert("所属app不能为空", {icon : 5,shift : 1});
					return;
				}
				if (null == codeName || '' == codeName || undefined == codeName) {
					layer.alert("代码名称不能为空", {icon : 5,shift : 1});
					return;
				}
				if (null == codeDesc || '' == codeDesc || undefined == codeDesc) {
					layer.alert("代码描述不能为空", {icon : 5,shift : 1});
					return;
				}
				submit();
			});
		});
	
		function submit() {
		    $.ajax({
		        type : "POST",
		        url : "${ctx}/code/addOrUpdateInfo",
		        data : $("#dataForm").serialize(),
		        success : function(data) {
		            if (data.status == "1") {
		            	layer.msg(data.message, {icon: 1, time: 1000}, function(){
		            		 parent.location.reload();
		            		 var index = parent.layer.getFrameIndex(window.name);
		            		 parent.layer.close(index);
		            	});
		            } else {
		                layer.alert(data.message, {icon : 5,shift : 1});
		            }
		        },
		        error : function(data, errorMsg) {
		            layer.alert("服务器异常" + errorMsg, {icon : 5,shift : 6});
		        }
		    });
		}
	</script>
</body>
</html>